package com.ipbd.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ipbd.domain.FirstAction;
import com.ipbd.mapper.FirstActionMapper;
import com.ipbd.service.FirstActionService;
import com.ipbd.utils.R;
import com.ipbd.utils.UserHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 86172
* @description 针对表【first_action(首次认知巩固)】的数据库操作Service实现
* @createDate 2024-03-06 20:53:48
*/
@Service
public class FirstActionServiceImpl extends ServiceImpl<FirstActionMapper, FirstAction> implements FirstActionService {

    /**
     * 填写并保存首次认知巩固
     * @param firstAction
     * @return
     */
    @Override
    public void saveFirst(FirstAction firstAction) {
        Integer id = UserHolder.getUser().getId();
        FirstAction action = new FirstAction();
        BeanUtil.copyProperties(firstAction, action);
        action.setUserId(id);
        save(action);
    }

    /**
     * 查询首次认知巩固
     * @return
     */
    @Override
    public R selectFirst() {
        Integer id = UserHolder.getUser().getId();
        List<FirstAction> firstActions = query().eq("user_id", id).list();
        return R.ok().put("firstActions", firstActions);
    }
}




